<?php

// TOOLS
include_once "application/tools/Page.php";
include_once "application/tools/Log.php";

// MODELS
include_once 'application/models/CSV.php';
include_once "application/models/Project.php";
include_once "application/models/Column.php";
include_once "application/models/Member.php";

// VIEWS
include_once "application/views/GrapheView.php";
include_once "application/views/AdminView.php";
include_once "application/views/ErrorView.php";

// CONTROLLERS
include_once 'application/controllers/GrapheController.php';
include_once 'application/controllers/AdminController.php';

/**
 * Classe principale de l'application WSK PORTAL
 */
class WSK {

    /**
     * fonction de lancement
     */
    public function run() {
		
        Authentification::setCurrentProjectId();
        $object = $this->getPageToDisplay();
	$object->render();
    }

    /**
     * Récupère la page àà afficher
     * @return \ErrorView
     */
    private function getPageToDisplay() {
        /**
         * récupère la page actuelle
         */
    	$page = Page::getCurrentPage();
        if(($page == Page::ADMIN && !Authentification::canAdminAcces()) || !Authentification::canProjectAcces()) {
            $page = Page::ERROR;
            //header('Location: main.php?page=-1');
        } 

        /**
         * En fonction de la page récupérée, afficher celle ci 
         */
        switch ($page) {
            case Page::ERROR:
            	$object = new ErrorView();
                break;
                
            case Page::GRAPH:
                //Log::createLog("message");
                $object = new GrapheView();
                GrapheController::save();
                break;

            case Page::ADMIN:                	
                $object = new AdminView();
                AdminController::save();
                break;

            default:
                $object = new ErrorView();
                break;
        }
        return $object;
    }

}